<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>引出生命周期</title>
		<script type="text/javascript" src="../js/vue.js"></script>
	</head>
	<body>
		<!-- 准备好一个容器-->
		<div id="root">
			<h1 :style="{opacity:tmd}">分手了怎么办？</h1>
			<button @click="death">不活了</button>
			<input type="text" v-model="name">
		</div>

		<script type="text/javascript" >
			const vm = new Vue({
				el:'#root',
				data:{
					tmd:1,
					name:''
				},
				methods:{
					death(){
						this.$destroy() //销毁vm上的数据监视
						// console.log(this)
					}
				},
				//挂载完毕
				mounted(){
					console.log('挂载完毕')
					this.timer = setInterval(() => {
						console.log('@@@')
						//获取原来透明度
						if(this.tmd <= 0 ) this.tmd = 1
						//递减
						this.tmd -= 0.01
					},16);
				},
				//将要销毁
				beforeDestroy(){
					clearInterval(this.timer)
				}
			})
		</script>
	</body>
</html>